package org.mobile.database.connection;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;


public class ConnectionManager {

	private static ConnectionManager manager = null;
	private Connection connection = null;
	private String url;
	private String username;
	private String password;

	private ConnectionManager() {
		try {
			Class.forName("com.mysql.jdbc.Driver").newInstance();
		} catch (InstantiationException e) {

			e.printStackTrace();
		} catch (IllegalAccessException e) {

			e.printStackTrace();
		} catch (ClassNotFoundException e) {

			e.printStackTrace();
		}
		username = "ti";
		password = "ti";
		url = "jdbc:mysql://localhost/ti_phones?characterEncoding=UTF-8";

	}

	public static ConnectionManager getManager() {
		if (manager == null) {
			manager = new ConnectionManager();
		}
		return manager;
	}

	public Connection getConnection() {

		try {
			if (connection == null || connection.isClosed()) {
				connection = DriverManager.getConnection(url, username,
						password);
			}
		} catch (SQLException e) {

			e.printStackTrace();
		}

		return connection;
	}

}
